import { HoudiniClient, type RequestHandler } from '$houdini';
import { PUBLIC_GRAFBASE_API_URL, PUBLIC_GRAFBASE_API_KEY } from '$env/static/public'

const requestHandler: RequestHandler = async ({
    fetch,
    text = '',
    variables = {},
    metadata
}) => {
    const url = "https://grafbasedemo-main-wgzxyouling.grafbase.app/graphql"
    const result = await fetch(url, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            "x-api-key": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2NzU3NTM2OTQsImlzcyI6ImdyYWZiYXNlIiwiYXVkIjoiMDFHUk5CODlGOVFFWkRLRjNNWkMyMFQ0RlciLCJqdGkiOiIwMUdSTkI4OUY5Q1c5TU45Nlo5NzJOTU5HMyIsImVudiI6InByb2R1Y3Rpb24iLCJwdXJwb3NlIjoicHJvamVjdC1hcGkta2V5In0.Lp6AxtOVstdzgryDwSHfpyfaLR5SIJm2ZkKnm2lZUSA"
        },
        body: JSON.stringify({
            query: text,
            variables,
        }),
    })

    return await result.json()
}

export default new HoudiniClient(requestHandler)
